package com.mingtu.jgspatrol.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.AppUtils;
import com.mingtu.jgspatrol.activity.LockScreenNewActivity;

/**
 * @ClassName :
 * @Author : wkk
 * @Date : 2024-7-1 17:02:38
 * @Email : 1281573890@qq.com
 * @Eescription :
 */
public class LockScreenBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
            //系统不会重复创建锁屏页，所以这里不用做相关判断
            Intent i = new Intent(ActivityUtils.getTopActivity(), LockScreenNewActivity.class);
            i.setPackage(AppUtils.getAppPackageName());
            i.setAction("com.android.lockscreen");
            i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
                    | Intent.FLAG_FROM_BACKGROUND
                    | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
                    | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
                    | Intent.FLAG_ACTIVITY_NO_ANIMATION
                    | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            ActivityUtils.getTopActivity().startActivity(i);
        }
    }
}
